package com.atguigu.srb.core.controller.api;


import com.atguigu.common.result.Result;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.VO.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ReactiveSubscription;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ZLHao
 * @since 2021-07-12
 */
@Api(tags = "借款人")
@Slf4j
@RestController
@RequestMapping("/api/core/borrower")
public class BorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @ApiOperation("保存借款人的信息")
    @PostMapping("/auth/save")
    public Result save(@RequestBody BorrowerVO borrowerVO , HttpServletRequest request){

        System.out.println("这是借款人的信息："+borrowerVO);

        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);

        borrowerService.save(borrowerVO,userId);
        return Result.ok().message("保存成功");

    }

    @ApiOperation("借款人的审核状态")
    @GetMapping("/auth/getBorrowerStatus")
    public Result getBorrowerStatus(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        Integer status =  borrowerService.getBorrowerStatus(userId);
        return Result.ok().data("borrowerStatus",status);
    }

}

